Test Series - Data Structure

Test Number 91/115

Q: Descending priority queue can be implemented using ______
A. max heap
B. min heap
C. min-max heap
D. trie
Solution: Descending priority queue arranges the elements based on their priority or value and allows removing the elements in descending order. So, it can be efficiently implemented using max heap.
Q: Min heap can be used to implement selection sort.
A. True
B. False
C. 
D. 
Solution:  In min heap, the insertion and deletion operation takes O(logn) time. Therefore, a selection sort with n insertions and n deletions can be implemented using a min heap in O(nlogn) operations.
Q: The procedure given below is used to maintain min-order in the min heap. Find out the missing statements, represented as X.

procedure TrickleDownMin(i)
	 if A[i] has children then 
		m := index of smallest of the children 
		        or grandchildren (if any) of A[i] 
		if A[m] is a grandchild of A[i] then
			 if A[m] < A[i] then 
				swap A[i] and A[m]
				X: _______________________
					____________________
			 endif 	
			TrickleDownMin(m)
		 endif 
		else //{A[m] is a child of A[i]} 
			if A[m] < A[i] then 
				swap A[i] and A[m] 
		endif
	 endif
A. if A[m] > A[parent(m)] then swap A[m] and A[parent(m)]
B. if A[m] > A[parent(m)] then swap A[i] and A[parent(m)]
C.  if A[m] < A[parent(m)] then swap A[m] and A[parent(m)]
D. if A[m] > A[parent(m)] then swap A[i] and A[parent(m)]
Solution:  In TrickleDownMin() procedure, we maintain the min-ordering of the min heap. In this procedure, we locate the lowest child or grandchild of the element at positions i. If the lowest element is grandchild then we check that it is smaller than both, its parent and A[i].
Q: The ascending heap property is ___________
A. A[Parent(i)] =A[i]
B. A[Parent(i)] <= A[i]
C. A[Parent(i)] >= A[i]
D. A[Parent(i)] > 2 * A[i]
Solution: The min heap is also known as ascending heap. Min heap of size n is an almost complete binary tree of n nodes such that the element at each node is greater than or equal to the element at its parent node.
Q: The procedure FindMin() to find the minimum element and the procedure DeleteMin() to delete the minimum element in min heap take _________
A. logarithmic and linear time constant respectively
B. constant and linear time respectively
C. constant and quadratic time respectively
D. constant and logarithmic time respectively
Solution: Which one of the following array elements represents a binary min heap?
Q: Which one of the following array elements represents a binary min heap?
A. 12 10 8 25 14 17
B. 8 10 12 25 14 17
C. 25 17 14 12 10 8
D. 14 17 25 10 12 8
Solution: A tree is min heap when data at every node in the tree is smaller than or equal to it’s children’ s data. So, only 8 10 12 25 14 17 generates required tree.
Q: In a binary min heap containing n elements, the largest element can be found in __________ time.
A. O(n)
B. O(nlogn)
C. O(logn)
D. O(1)
Solution: In min heap the smallest is located at the root and the largest elements are located at the leaf nodes. So, all leaf nodes need to be checked to find the largest element. Thus, worst case time will be O (n).
Q: Min heap is a complete binary tree.
A. True
B. False
C. 
D. 
Solution: A tree, in which all levels are fully filled, except possibly the last level, is called as the complete binary tree. And min heap maintains shape property, so it is a complete binary tree. The shape property ensures that all levels in the min heap are fully filled, except the last one, and, if the last level is not filled completely, then fill the elements from left to right.
Q: What will be the position of 5, when a max heap is constructed on the input elements 5, 70, 45, 7, 12, 15, 13, 65, 30, 25?
A. 5 will be at root
B. 5 will be at last level
C. 5 will be at second level
D. 5 can be anywhere in heap
Solution: In max heap the greatest element is at the root and the smallest elements are at the last level. As 5 is the smallest input element, it will be at the last level.
Q: 
A. 
B. 
C. 
D. 
Solution: 

You Have Score    /10